package com.punai.standard.controller;

import com.punai.common.bos.HeaderBo;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.domain.TreeBo;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.utils.StringUtils;
import com.punai.standard.domain.vo.StaFeeVo;
import com.punai.standard.service.IStaFbChapterService;
import com.punai.standard.service.IStaGxChapterService;
import com.punai.standard.service.StaSubpkLinkConsumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/sta/fee/")
public class LwZyFeeController extends BaseController {

    @Autowired
    private IStaFbChapterService staFbChapterService;
    @Autowired
    private IStaGxChapterService staGxChapterService;

    @Autowired
    private StaSubpkLinkConsumeService staSubpkLinkConsumeService;

    @PreAuthorize("@ss.hasPermi('sta:gxfee:list')")
    @GetMapping("/gxTreeData/{versionId}")
    public AjaxResult gxTreeData(@PathVariable String versionId)
    {
        List<TreeBo> list = staGxChapterService.treeData(versionId,getCompanyId());
        return AjaxResult.success(list);
    }

    @GetMapping("/getAddressByVersionsId/{versionId}")
    public AjaxResult getAddressByVersionId(@PathVariable("versionId") String versionId)
    {
        return  AjaxResult.success(staGxChapterService.selectAddressByVersionId(versionId));
    }

    @PreAuthorize("@ss.hasPermi('sta:fbfee:list')")
    @GetMapping("/fbTreeData/{versionId}")
    public AjaxResult fbTreeData(@PathVariable String versionId)
    {
        List<TreeBo> list = staFbChapterService.treeData(versionId,getCompanyId());
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('sta:gxfee:list')")
    @GetMapping("/feeGxList")
    public TableDataInfo feeGxList(StaFeeVo vo)
    {
        if (StringUtils.isEmpty(vo.getChapterId())) {
            return getDataTable(new ArrayList<>());
        }
        return staGxChapterService.feeList(vo,getCompanyId());
    }

    @PreAuthorize("@ss.hasPermi('sta:fbfee:list')")
    @GetMapping("/feeFbList")
    public TableDataInfo feeFbList(StaFeeVo vo)
    {
        if (StringUtils.isEmpty(vo.getChapterId())) {
            return getDataTable(new ArrayList<>());
        }
        return staFbChapterService.feeList(vo,getCompanyId());
    }


    // 这个应该也用不着了
    @GetMapping("/getCategoryHeader/{versionId}")
    public AjaxResult getCategoryHeader(@PathVariable String versionId) {
        List<HeaderBo> res = staSubpkLinkConsumeService.getCategoryHeader(versionId);
        return AjaxResult.success(res);
    }

    @GetMapping("/listConsume/{linkGxFeatureId}/{versionId}/{address}")
    public TableDataInfo listConsume(@PathVariable("linkGxFeatureId") String linkGxFeatureId,@PathVariable("versionId") String versionId,@PathVariable("address") String address)
    {
        if (StringUtils.isEmpty(versionId)||StringUtils.equals(versionId,"null")) {
            throw new RuntimeException("版本号为空");
        }
        return getDataTable(staSubpkLinkConsumeService.listConsume(linkGxFeatureId,address,versionId,getCompanyId()));
    }

}
